package com.estronger.shopmanage.ui.othertask.activity;


import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.ui.othertask.fragment.BaseOtherTaskMainFragment;
import com.estronger.shopmanage.ui.othertask.fragment.OtherTaskMainFragment1;
import com.estronger.shopmanage.ui.othertask.fragment.OtherTaskMainFragment2;
import com.estronger.shopmanage.ui.othertask.fragment.OtherTaskMainFragment3;
import com.estronger.shopmanage.ui.othertask.presenter.OtherTaskMainPresenter;
import com.soonfor.evaluate.adapter.FragmentAdapter;
import com.soonfor.evaluate.base.EvalBaseActivity;
import com.soonfor.evaluate.tools.Tokens;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by DingYg on 2018-01-29.
 * 其它任务
 */

public class OtherTaskMainActivity extends EvalBaseActivity<OtherTaskMainPresenter> {

    private String[] titles = new String[]{"进行中", "已逾期", "已完成"};
    private BaseOtherTaskMainFragment bgFrament1, bgFrament2, bgFrament3;
    private FragmentAdapter adapter;
    //ViewPage选项卡页面列表
    private List<Fragment> mFragments;
    private List<String> mTitles;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    public static int fragmentPositon = 0;// 第一次进入的是哪个Fragment
    public static int ItemPosition = -1;
    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_tablayout_fixed;
    }

    @Override
    protected void initPresenter() {
        presenter = new OtherTaskMainPresenter(this);
    }

    @Override
    protected void initViews() {
        ((TextView) toolbar.findViewById(R.id.tvfTitile)).setText("其它任务");
        mTitles = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            mTitles.add(titles[i]);
        }
        mFragments = new ArrayList<>();
        bgFrament1 = new OtherTaskMainFragment1();
        bgFrament2 = new OtherTaskMainFragment2();
        bgFrament3 = new OtherTaskMainFragment3();

        mFragments.add(bgFrament1);
        mFragments.add(bgFrament2);
        mFragments.add(bgFrament3);

        adapter = new FragmentAdapter(getSupportFragmentManager(), mFragments, mTitles);
        viewPager.setAdapter(adapter);//给ViewPager设置适配器
        tablayout.setupWithViewPager(viewPager);//将TabLayout和ViewPager关联起来
        fragmentPositon = getIntent().getIntExtra(Tokens.OtherTask.SKIPTOFRAGMENT_STATUS, 0);
        viewPager.setCurrentItem(fragmentPositon,false);
        viewPager.setOffscreenPageLimit(2);
    }

    public void setNumToTitles(int[] nums){
        if(mTitles==null) mTitles = new ArrayList<>();
        else if(mTitles.size()>0) mTitles.clear();
        mTitles.add("进行中("+ nums[0] + ")");
        mTitles.add("已逾期("+ nums[1] + ")");
        mTitles.add("已完成("+ nums[2] + ")");
//        if(nums[0]>0) mTitles.add("进行中("+ nums[0] + ")");
//        else mTitles.add("进行中");
//        if(nums[1]>0) mTitles.add("已逾期("+ nums[1] + ")");
//        else mTitles.add("已逾期");
//        if(nums[2]>0) mTitles.add("已完成("+ nums[2] + ")");
//        else mTitles.add("已完成");
       adapter.setTitles(mTitles);
    }

    @Override
    protected void updateViews(boolean isRefresh) {}

    @Override
    protected void onResume() {
        super.onResume();
        presenter.getTaskNum(this, 0);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
